package com.tjl.warehouse.controller;

import com.tjl.warehouse.annotation.AuthToken;
import com.tjl.warehouse.common.R;
import com.tjl.warehouse.exception.ThrowUtils;
import com.tjl.warehouse.model.InStore;
import com.tjl.warehouse.model.MyPage;
import com.tjl.warehouse.model.OutStore;
import com.tjl.warehouse.model.Store;
import com.tjl.warehouse.model.dto.InStoreReq;
import com.tjl.warehouse.model.dto.OutStoreReq;
import com.tjl.warehouse.service.OutStoreService;
import com.tjl.warehouse.service.StoreService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Tang
 */
@RestController
@Slf4j
@Tag(name = "出库接口")
@AuthToken
@RequestMapping("/outstore")
public class OutStoreController {


    @Resource
    StoreService storeService;
    @Resource
    OutStoreService outStoreService;

    //获取入库记录
    @GetMapping("/outstore-page-list")
    public R<MyPage<OutStore>> getInStoreList(OutStoreReq req, MyPage<OutStore> page) {
        //检查参数
        ThrowUtils.throwIfParams(page == null);
        ThrowUtils.throwIfParams(page.getPageNum() <= 0, "页码最小为1");
        ThrowUtils.throwIfParams(page.getPageSize() >= 500, "最大每页500条");

        MyPage<OutStore> pageList = outStoreService.getPageList(req, page);
        return R.success(pageList);
    }

    //获取仓库
    @GetMapping("/store-list")
    public R<List<Store>> getStoreList() {
        return R.success(storeService.list());
    }


}
